{include file="public/meta" /} 

<title>编辑系统分类</title>
</head>
<body>
    <article class="cl pd-20">
        <form class="form form-horizontal" id="form-member-add">
            <input type="hidden" id="category_id" name="category_id" value="{$info['id']}" />
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>所属父级：</label>
                <div class="formControls col-xs-8 col-sm-9"> <span class="select-box">
                    <select class="select" size="1" name="parent_id" id="parent_id">
                        <option value="0" selected>无父级分类</option>
                        {volist name="categoryList" id="val"}
                        <option value="{$val['id']}">{$val['title']}</option>
                        {/volist}
                    </select>
                    </span> </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>分类别名：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="text" class="input-text" value="{$info['call_index']}" placeholder="只能由小写英文字母组成" id="callindex" name="callindex">
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>分类名称：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="text" class="input-text" value="{$info['title']}" placeholder="汉字组成" id="title" name="title">
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3">分类图片：</label>
                <div class="formControls col-xs-8 col-sm-9"> <span class="btn-upload form-group">
                    <input class="input-text upload-url" type="text" name="img_url" id="img_url" value="{$info['img_url']}" nullmsg="请添加分类图片" style="width:400px">
                    <a href="javascript:void();" class="btn btn-primary radius upload-btn"><i class="Hui-iconfont">&#xe642;</i> 选择图片</a>
                    <input type="file" name="file-2" class="input-file">
                    </span> </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>排序数字：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="text" class="input-text" value="{$info['sort']}" placeholder="只能填写大于等于0的数字" id="sort" name="sort">
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>备注说明：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="text" class="input-text" value="{$info['description']}" placeholder="分类描述" id="description" name="description">
                </div>
            </div>
            <div class="row cl">
                <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                    <input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;保存修改&nbsp;&nbsp;">
                </div>
            </div>
        </form>
    </article>

<!--_footer 作为公共模版分离出去-->
{include file="public/footer" /} 
<!--/_footer /作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="__LIB__/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="__LIB__/jquery.validation/1.14.0/jquery.validate.js"></script> 
<script type="text/javascript" src="__LIB__/jquery.validation/1.14.0/validate-methods.js"></script> 
<script type="text/javascript" src="__LIB__/jquery.validation/1.14.0/messages_zh.js"></script> 
<script type="text/javascript">
$(function(){
	$('.skin-minimal input').iCheck({
		checkboxClass: 'icheckbox-blue',
		radioClass: 'iradio-blue',
		increaseArea: '20%'
	});

    $('.input-file').change(function(){
        var filess=$('.input-file')[0].files[0]
        console.log(filess);
        var fm=new FormData();
        fm.append('image',filess);

        $.ajax({
                type: 'post', 
                url: '{:url('Common/uploadImage')}', 
                data: fm,
                processData: false,
                contentType: false,
                success: function(data) { 
                    //alert(data);
                    var jdata=JSON.parse(data);
                    if(jdata.code==0)
                    {
                        parent.layer.msg(jdata.msg,{icon:6,time:1000});
                        var imgurl=jdata.data;
                        imgurl= imgurl.replace(/\\/g, "/");
                        $('#img_url').val(imgurl);
                    }
                    else
                    {
                        parent.layer.msg(jdata.msg,{icon:5,time:1000});
                    }
                    
                },
                error:function(data){
                    layer.msg('500系统错误，请重试！',{icon:5,time:1000});
                }
            });

    });

    $("#parent_id").val({$info['parent_id']});
	
	$("#form-member-add").validate({
		rules:{
			callindex:{
				required:true,
				minlength:2,
				maxlength:30
			},
            title:{
				required:true,
				minlength:2,
				maxlength:16
			},
			description:{
				required:true,
				minlength:1,
				maxlength:500
			},
			sort:{
				required:true,
				digits:true,
			},
		},
		onkeyup:false,
		focusCleanup:true,
		success:"valid",
		submitHandler:function(form){
			
            $.ajax({
                type: 'post', 
                url: '{:url('System/categoryEditSave')}', 
                data: {
                    'category_id':$('#category_id').val(),
                    'call_index': $('#callindex').val(),
                    'title': $('#title').val(),
                    'sort': $('#sort').val(),
                    'description':$('#description').val(),
                    'parent_id':$('#parent_id').val(),
                    'img_url':$('#img_url').val()
                },
                dataType:'json',
                success: function(data) { 
                    if(data.code==0)
                    {
                        parent.layer.msg(data.msg,{icon:6,time:1000});
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.window.location.reload();
                        parent.layer.close(index);
                    }
                    else
                    {
                        parent.layer.msg(data.msg,{icon:5,time:1000});
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                    }
                    
                },
                error:function(data){
                    layer.msg('500系统错误，请重试！',{icon:5,time:1000});
                }
            });

		}
	});
});
</script> 
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>